/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ServerView.java
 *
 * Created on 13/10/2009, 10:01:07 PM
 */

package server.View;

import common.UCM.UC2AL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import server.UCM.UCStartServer;
import server.UCM.UCStopServer;

/**
 *
 * @author Slasher
 */
public class ServerView extends javax.swing.JFrame {

    /** Creates new form ServerView */
    private static ServerView instance;
    private ServerView() {
        initComponents();
        setLocationRelativeTo(null);
        serverStartButton.addActionListener(new UC2AL(new UCStartServer()));
        serverStopButton.addActionListener(new UC2AL(new UCStopServer()));
    }
    public static ServerView getInstance() {
        if (instance == null) {
            instance = new ServerView();
        }
        return instance;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        serverStartButton = new javax.swing.JButton();
        serverStopButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        serverStatusTextArea = new javax.swing.JTextArea();
        titleLable = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Java Server");

        serverStartButton.setText("Start");

        serverStopButton.setText("Stop");

        jScrollPane1.setHorizontalScrollBar(null);

        serverStatusTextArea.setColumns(20);
        serverStatusTextArea.setEditable(false);
        serverStatusTextArea.setLineWrap(true);
        serverStatusTextArea.setRows(5);
        serverStatusTextArea.setWrapStyleWord(true);
        jScrollPane1.setViewportView(serverStatusTextArea);

        titleLable.setText("<- Java Sever ->");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(79, 79, 79)
                        .addComponent(serverStartButton)
                        .addGap(18, 18, 18)
                        .addComponent(titleLable)
                        .addGap(18, 18, 18)
                        .addComponent(serverStopButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(titleLable)
                    .addComponent(serverStopButton)
                    .addComponent(serverStartButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton serverStartButton;
    private javax.swing.JTextArea serverStatusTextArea;
    private javax.swing.JButton serverStopButton;
    private javax.swing.JLabel titleLable;
    // End of variables declaration//GEN-END:variables

    public void addToDisplayArea(String text) {
        DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        Date date = new Date();
        serverStatusTextArea.append(dateFormat.format(date) + ": " + text + "\n");
        serverStatusTextArea.setCaretPosition(serverStatusTextArea.getText().length());
    }

    public void loadView() {
        this.setVisible(true);
    }

}
